package com.yang.booking.service;

import com.yang.booking.dao.StaffItemMapper;
import com.yang.booking.pojo.StaffItem;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Service
public class StaffItemService {

    @Autowired
    private StaffItemMapper staffItemMapper;

    @Transactional
    public Map<String, Object> insertStaffItem(String staffIdList, String itemIdList){

        for (String staffId: staffIdList.split(",")) {
            HashMap<String, Object> map = new HashMap<>();
            map.put("staff_id", staffId);
            staffItemMapper.deleteByMap(map);

            for (String itemId: itemIdList.split(",")) {
                StaffItem si = new StaffItem();
                si.setStaffId(staffId);
                si.setItemId(itemId);
                si.setCreateAt(new Date());
                si.setUpdateAt(new Date());
                staffItemMapper.insert(si);
            }
        }

        Map<String, Object> msg = new HashMap<String, Object>();
        msg.put("massage", "插入成功");
        msg.put("code", 200);
        return msg;
    }
}
